package com.example.woke;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;

import com.http.HttpMethods;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.PersistentCookieStore;
import com.loopj.android.http.RequestParams;
import com.woke.data.Datas_myinfo;
import com.woke.method.Intentnet;
import com.zhongcai.online.R;

import org.apache.http.Header;
import org.json.JSONException;
import org.json.JSONObject;

public class MyinfoinfoActivity extends Activity {

	private TextView mTextView1,mTextView2,mTextView3,mTextView4;
	private String id;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_myinfoinfo);
		
		
		Intent intent = getIntent();
		Datas_myinfo data = (Datas_myinfo) intent.getSerializableExtra("data_myinfo");
//		String title = intent.getStringExtra("title");
//		String addtime = intent.getStringExtra("addtime");
//		String content = intent.getStringExtra("content");
		id = data.getId();
//		id = intent.getStringExtra("id");
		
		mTextView1 = (TextView) findViewById(R.id.avmyinfoinfo_text1);
		mTextView2 = (TextView) findViewById(R.id.avmyinfoinfo_text2);
		mTextView3 = (TextView) findViewById(R.id.avmyinfoinfo_text3);
		mTextView4 = (TextView) findViewById(R.id.avmyinfoinfo_text4);
		
//		String type = data.getType();
//		//1ϵͳ2���3֧��4����
//		if(type.equals("1")){
//			mTextView2.setText("系统");
//		}if(type.equals("2")){
//			mTextView2.setText("借贷");
//		}if(type.equals("3")){
//			mTextView2.setText("支付");
//		}if(type.equals("4")){
//			mTextView2.setText("其他");
//		}
		mTextView2.setText(data.getType_info());
		mTextView1.setText(data.getTitle());
		String strTime1 = Intentnet.getStrTime1(data.getAddtime());
		mTextView3.setText(data.getContent());
		mTextView4.setText(strTime1);
		
		findViewById(R.id.avmyinfoinfo_image_back).setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		
		sendreadinfo();
		
	}
	
	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		
		setResult(10);
	}

	private void sendreadinfo() {
		AsyncHttpClient ahc = new AsyncHttpClient();
		PersistentCookieStore myCookieStore = new PersistentCookieStore(MyinfoinfoActivity.this);    
        ahc.setCookieStore(myCookieStore); 
		RequestParams params = new RequestParams();
		params.put("g", "api");
		params.put("m", "message");
		params.put("a", "markReadOrDel");
		params.put("ids", id);
		params.put("marktype", "read");
		
		ahc.get(HttpMethods.BASEURL, params, new JsonHttpResponseHandler(){
			@Override
			public void onSuccess(int statusCode, Header[] headers,
					JSONObject response) {
				super.onSuccess(statusCode, headers, response);
//				Log.e("�ҵ���Ϣ", ""+response);
				try {
					String flag = response.getString("flag");
					if(flag.equals("success")){
						
					}
				} catch (JSONException e) {
					e.printStackTrace();
				}
			}
			
			@Override
			public void onFailure(int statusCode, Header[] headers,
					String responseString, Throwable throwable) {
				super.onFailure(statusCode, headers, responseString, throwable);
				Toast.makeText(MyinfoinfoActivity.this, "失败！", Toast.LENGTH_SHORT).show();
				Log.e("response", "失败"+responseString);
			}
			
			@Override
			public void onStart() {
				// TODO Auto-generated method stub
				super.onStart();
//				mBar.setVisibility(View.VISIBLE);
			}
			
			@Override
			public void onFinish() {
				super.onFinish();
//				mBar.setVisibility(View.GONE);
				Log.e("response", "完成");
			}
		});
	}
}
